package com.welsy.classroom.business
{
	import mx.controls.Alert;
	import com.welsy.usermgt.vo.UserVO;
	import com.adobe.cairngorm.business.ServiceLocator;
	import mx.rpc.soap.mxml.WebService;
	import mx.rpc.AbstractOperation;
	import mx.rpc.AsyncToken;
	import mx.rpc.IResponder;
	import mx.logging.Log;
	import com.welsy.usermgt.vo.ClassVO;
	import flash.xml.XMLNode;
	import mx.collections.ArrayCollection;
	import mx.rpc.soap.Operation;
	import com.welsy.util.NamespaceLocator;
	import com.welsy.iter.vo.IterVO;

	
	public class AddNewsDelegate 
	{
		private var responder : IResponder;
		private var service : Object;
		
		public function AddNewsDelegate( responder : IResponder ) {
			//Recorded in Services.mxml
			this.responder = responder;
			this.service = ServiceLocator.getInstance().getWebService("NewsService") as WebService;
		}
				
		public function addNews(newsId : String, title : String, descr : String, creationDate : String, authorId : String, classIds : ArrayCollection) : void {
			var oper : Operation = Operation(WebService(service).getOperation("SaveNews"));
			var root : String = "<SaveNews xmlns='http://Welsy.ServiceContracts/2007/02'>";
			root += "<SaveNewsRequest xmlns='"+NamespaceLocator.NEWS_DATATYPES+"'>";
			
			root += "<News>";
			root += "<NewsId>" + newsId + "</NewsId>";
			root += "<Title>" + title + "</Title>";
			root += "<Description>" + descr + "</Description>";
			root += "<CreationDate>" + creationDate + "</CreationDate>";
			root += "<AuthorId>" + authorId + "</AuthorId>";
			root += "</News>"
			root += "<Classrooms>";
			
			for each(var id : int in classIds) {
				root += "<decimal>" + id + "</decimal>";				
			}
			
			root += "</Classrooms>";
			root += "</SaveNewsRequest></SaveNews>";	
			oper.request = new XML(root);
			var token : AsyncToken = service["SaveNews"].send();
			token.addResponder(responder);				
		}
	}	
}